package com.dc.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *  船体下料  单船工序
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_workflow_ship_cut")
public class WorkflowShipCutEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "submit_time")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date submitTime = new Date();        // 填写日期

    @Transient
    private Long shipRepairId;      // 维修记录 外键id

    @Transient
    private String shipName;        // 船体名称

    @Transient
    private String reporter;        // 填报人

    @Column(name = "room", length = 50)     // 车间
    private String room;
    ////////////////////////////////////////////////////

    @Column(name = "weight")
    // 填写
    private Double weight;          // 钢板重量(吨)

    @Transient
    private Double powers;          // 使用电量     //动态计算

    @Transient
    private Double powersByUnit;    // 单位用电量    //动态计算

    @Column(name = "ship_weight")
    // 填写
    private Double shipWeight;      // 单船下料钢板重量(吨)

    @Transient
    private Double shipPowers;      // 单船下料用电量  //动态计算

    @Transient
    private Double o2ByUnit;        // 单位耗氧气量标定值        // 工序标定动态计算

    @Transient
    private Double o2;              // 氧气量                  // 动态计算

    @Transient
    private Double airByUnit;       // 单位耗压缩空气量标定值      // 工序标定动态计算

    @Transient
    private Double air;             // 压缩空气量                // 动态计算

    @Column(name = "create_time")
    @CreationTimestamp
    private Date createTime;

    /////////////////////////////////////////////////////////////////////
    @JsonIgnoreProperties(value = { "workflowShipCutEntity" })
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @JoinColumn(name = "workflow_ship_cut_id", referencedColumnName = "id")
    private List<WorkflowShipCutChildEntity> inner = new ArrayList<>();


    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ship_repair_id", columnDefinition = "bigint unsigned NOT NULL")
    private ShipRepairEntity shipRepairEntity;
}
